package utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 ** PropertiesUtils class
 *
 *读取临时文件的类
 *
 * @author wangfei
 * @date 2019/07/10
 */
public class PropertiesUtils {
    private static final Logger log = LoggerFactory.getLogger(PropertiesUtils.class);
    private Properties props;
    public PropertiesUtils(String path){
        InputStream is = null;
        try {
            is = new FileInputStream(path);
            InputStreamReader isr = new InputStreamReader(is, "UTF-8");
            props = new Properties();
            props.load(isr);
        }catch (IOException e){
            log.error("PropertiesUtils初始化异常：{}",e.getMessage());
        }finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public String get(String key){
        return props==null?null:props.getProperty(key);
    }
}
